<?php
/*
File: index.php
Version: 2.0
Date created: 
Last Edited : 26-07-2008
Author: Craig G Smith<craig@joomla-host.co.za
*/

  defined( 'JOSCOM_VERSION' ) or die( 'Direct Access to this location is not allowed.' );
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      tep_db_connect() or die('Unable to connect to database server!');
    }
    global $category_links, $languages_id, $cPath, $cPath_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    require(DIR_WS_COMPONENT . 'includes/application_top.php');
  }
  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  $languages = tep_get_languages();
  $languages_array = array();
  $languages_selected = DEFAULT_LANGUAGE;
  for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
    $languages_array[] = array('id' => $languages[$i]['code'],
                               'text' => $languages[$i]['name']);
    if ($languages[$i]['directory'] == $language) {
      $languages_selected = $languages[$i]['code'];
    }
  }
  
$counter_query = tep_db_query("select startdate, counter from " . TABLE_COUNTER);
  $counter = tep_db_fetch_array($counter_query);
  $counter_startdate = $counter['startdate'];

  $counter_startdate_formatted = strftime(DATE_FORMAT_SHORT, mktime(0, 0, 0, substr($counter_startdate, 4, 2), substr($counter_startdate, -2), substr($counter_startdate, 0, 4)));

$customers_query = tep_db_query("select count(*) as count from " . TABLE_CUSTOMERS);
  $customers = tep_db_fetch_array($customers_query);
  $products_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS . " where products_status = '1'");
  $products = tep_db_fetch_array($products_query);
  $products_off_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS . " where products_status = '0'");
  $products_off = tep_db_fetch_array($products_off_query);
  $reviews_query = tep_db_query("select count(*) as count from " . TABLE_REVIEWS);
  $reviews = tep_db_fetch_array($reviews_query);
  $reviews_noquery = tep_db_query("select count(*) as count from " . TABLE_REVIEWS . " where approved = '0'");
  $reviews_pending = tep_db_fetch_array($reviews_noquery);  
  $newsletters_query = tep_db_query("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'");
  $newsletters = tep_db_fetch_array($newsletters_query);
  $specials = tep_db_fetch_array(tep_db_query("select count(*) as count from " . TABLE_SPECIALS . " where status= '0'"));
  $specials_act = tep_db_fetch_array(tep_db_query("select count(*) as count from " . TABLE_SPECIALS . " where status= '1'"));
  
?>
<style type="text/css"><!--
a { color:#080381; text-decoration:none; }
a:hover { color:#aabbdd; text-decoration:underline; }
a.text:link, a.text:visited { color: #000000; text-decoration: none; }
a:text:hover { color: #000000; text-decoration: underline; }
a.osc_main:link, a.main:visited { color: #ffffff; text-decoration: none; }
A.osc_main:hover { color: #ffffff; text-decoration: underline; }
a.sub:link, a.sub:visited { color: #dddddd; text-decoration: none; }
A.sub:hover { color: #dddddd; text-decoration: underline; }
.heading { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 20px; font-weight: bold; line-height: 1.5; color: #D3DBFF; }
.osc_main { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 17px; font-weight: bold; line-height: 1.5; color: #ffffff; }
.sub { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; line-height: 1.5; color: #dddddd; }
.text { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height: 1.5; color: #000000; }
.menuBoxHeading { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #ffffff; font-weight: bold; background-color: #7187bb; border-color: #7187bb; border-style: solid; border-width: 1px; }
.infoBox { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #080381; background-color: #f2f4ff; border-color: #7187bb; border-style: solid; border-width: 1px; }
.smallText { font-family: Verdana, Arial, sans-serif; font-size: 10px; }
//--></style>
<?php include(DIR_WS_COMPONENT . 'includes/header.php'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_COMPONENT ?>includes/stylesheet.css">
<script language="javascript" src="<?php echo DIR_WS_COMPONENT ?>includes/general.js"></script>
 <table width="100%" border="0" cellpadding="4" cellspacing="0"  class="adminlist"><thead>
  <tr>
    <th width="33%"><?php echo BOX_TITLE_STATISTICS; ?></th>
    <th width="34%"><?php echo BOX_TITLE_ORDERS; ?></th>
    <th width="33%"><?php echo BOX_ENTRY_NEW_CUSTOMERS; ?></th>
  <tr> </thead>
  <tr valign="top">
    <td rowspan="3">
      <table width="100%">
        <tr>
          <td><?php echo BOX_ENTRY_COUNTER_DATE ?></td>
          <td><?php echo $counter_startdate_formatted;?></td>
        </tr>
        <tr>
          <td><?php echo BOX_ENTRY_COUNTER ?></td>
          <td><?php echo $counter['counter'];?></td>
        </tr>
        <tr>
          <td><a href="<?php echo tep_href_link(FILENAME_CUSTOMERS, 'selected_box=customers')?>"><?php echo BOX_ENTRY_CUSTOMERS ?></a></td>
          <td><?php echo $customers['count'] ?></td>
        </tr>
        <tr>
          <td><?php echo BOX_ENTRY_PRODUCTS ?></td>
          <td><?php echo $products['count'] ?></td>
        </tr>
        <tr>
          <td><?php echo BOX_ENTRY_PRODUCTS_OFF ?></td>
          <td><?php echo $products_off['count'] ?></td>
        </tr>
        <tr>
          <td><?php echo BOX_ENTRY_REVIEWS ?></td>
          <td><?php echo $reviews['count'] ?></td>
        </tr>
        <tr>
          <td><?php echo '<a href="' . tep_href_link(FILENAME_REVIEWS, 'status=1', 'NONSSL') . '">' . BOX_ENTRY_REVIEWS_PENDING . '</a>'; ?></td>
          <td><?php echo $reviews_pending['count'];?></td>
        </tr>
        <tr>
          <td><?php echo BOX_ENTRY_NEWSLETTERS; ?></td>
          <td><?php echo $newsletters['count'] ?></td>
        </tr>
        <tr>
          <td><?php echo BOX_ENTRY_SPECIALS_ACTIVE ?></td>
          <td><?php echo $specials_act['count']; ?></td>
        </tr>
        <tr>
          <TD><?php echo BOX_ENTRY_SPECIALS_EXPIRED ?></td>
          <td><?php echo $specials['count']; ?></td>
        </tr>
        
        <?php
        $affiliate_sales_raw = "select count(*) as count, sum(affiliate_value) as total, sum(affiliate_payment) as payment from " . TABLE_AFFILIATE_SALES . " ";
$affiliate_sales_query= tep_db_query($affiliate_sales_raw);
$affiliate_sales= tep_db_fetch_array($affiliate_sales_query);
$affiliate_clickthroughs_raw = "select count(*) as count from " . TABLE_AFFILIATE_CLICKTHROUGHS . " ";
$affiliate_clickthroughs_query=tep_db_query($affiliate_clickthroughs_raw);
$affiliate_clickthroughs= tep_db_fetch_array($affiliate_clickthroughs_query);
$affiliate_clickthroughs=$affiliate_clickthroughs['count'];
$affiliate_transactions=$affiliate_sales['count'];
if ($affiliate_transactions>0) {
	$affiliate_conversions = tep_round($affiliate_transactions/$affiliate_clickthroughs,6)."%";
}
else $affiliate_conversions="n/a";
$affiliate_amount=$affiliate_sales['total'];
if ($affiliate_transactions>0) {
	$affiliate_average=tep_round($affiliate_amount/$affiliate_transactions,2);
}
else {
	$affiliate_average="n/a";
}
$affiliate_commission=$affiliate_sales['payment'];
$affiliates_raw = "select count(*) as count from " . TABLE_AFFILIATE . "";
$affiliates_raw_query=tep_db_query($affiliates_raw);
$affiliates_raw = tep_db_fetch_array($affiliates_raw_query);
$affiliate_number= $affiliates_raw['count'];
?>
<tr>
  <td><?php echo BOX_ENTRY_AFFILIATES; ?></td>
  <td><?php echo $affiliate_number;?></td>
</tr>
<tr>
  <td><?php echo BOX_ENTRY_CONVERSION; ?></td>
  <td><?php echo $affiliate_conversions;?></td>
</tr>
<tr>
  <td><?php echo BOX_ENTRY_COMMISSION; ?></td>
  <td><?php echo $currencies->display_price($affiliate_commission, '');?></td>
</tr>
<tr>
  <td><?php echo BOX_ENTRY_SUPPLIERS; ?></td>
  <td><?php
  $supp_count = tep_db_fetch_array(tep_db_query("select count(*) as count from " . TABLE_SUPPLIERS));
  echo $supp_count['count'];
  ?>
  </td></tr>
  <tr>
  <td><?php echo BOX_CATALOG_AUCTIONS_PRODUCTS; ?></td>
  <td><?php
  $auc_count = tep_db_fetch_array(tep_db_query("select count(*) as count from " . TABLE_AUCTIONS_PRODUCTS));
  echo $auc_count['count'];
  ?>
  </td></tr>
        
      </table>
      </td>
      <td valign="top">
      <table width="100%">
      <?php
      $orders_status_query = tep_db_query("select orders_status_name, orders_status_id from " . TABLE_ORDERS_STATUS . " where language_id = '" . $languages_id . "'");
  while ($orders_status = tep_db_fetch_array($orders_status_query)) {
    $orders_pending_query = tep_db_query("select count(*) as count from " . TABLE_ORDERS . " where orders_status = '" . $orders_status['orders_status_id'] . "'");
    $orders_pending = tep_db_fetch_array($orders_pending_query);
    
    echo '<tr><td><a href="' . tep_href_link(FILENAME_ORDERS, 'selected_box=customers&status=' . $orders_status['orders_status_id']) . '">' . $orders_status['orders_status_name'] . '</a></td><td>' . $orders_pending['count'] . '</td></tr>';
  }
  
  ?>
      </table>
      </td>
      <td>
     <table width="100%">
  <?php  $customers_query = tep_db_query("select c.customers_id as customers_id, c.customers_firstname as customers_firstname, c.customers_lastname as customers_lastname, a.customers_info_date_account_created as customers_info_date_account_created, a.customers_info_id from " . TABLE_CUSTOMERS . " c left join " . TABLE_CUSTOMERS_INFO . " a on c.customers_id = a.customers_info_id order by a.customers_info_date_account_created DESC limit 5");

  while ($customers = tep_db_fetch_array($customers_query)) {
    echo '              <tr><td><a href="' . tep_href_link(FILENAME_CUSTOMERS, 'search=' . $customers['customers_lastname'] . '&origin=' . FILENAME_DEFAULT, 'NONSSL') . '" class="contentlink">'. $customers['customers_firstname'] . ' ' . $customers['customers_lastname'] . '</a></td><td>';
    echo tep_date_short($customers['customers_info_date_account_created']);
    echo '              </td></tr>';
  }
?>
</table>
      
      </td>
         
   </tr>
   <tr>
   <td colspan="2"><table class="adminlist">
   <thead>
   <tr>
    <th width="34%"><?php echo BOX_ENTRY_NEW_ORDERS; ?></th>
    <th width="33%"><?php echo BOX_ENTRY_TOP_SELLERS; ?></th>
   </tr>
   </thead>
   
   <tr valign="top">
    <td>
    <table width="100%">
    <?php  
    $orders_query = tep_db_query("select o.orders_id as orders_id, o.customers_name as customers_name, o.customers_id, o.date_purchased as date_purchased, o.currency, o.currency_value, ot.class, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id) where class = 'ot_total' order by orders_id DESC limit 5");

  while ($orders = tep_db_fetch_array($orders_query)) {
    echo '              <tr><td><a href="' . tep_href_link(FILENAME_ORDERS, 'oID=' . $orders['orders_id'] . '&origin=' . FILENAME_DEFAULT, 'NONSSL') . '" class="contentlink"> ' . $orders['customers_name'] . '</a></td><td>' . $orders['order_total'] . '</td><td>';
    echo tep_date_short($orders['date_purchased']);
    echo '              </td></tr>' . "\n";

  }
?>
</table>
</td>
    <td>
    <table>
    <?php
    $products_query_raw = tep_db_query("select p.products_id, p.products_ordered, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where pd.products_id = p.products_id and pd.language_id = '" . $languages_id. "' and p.products_ordered > 0 group by pd.products_id order by p.products_ordered DESC, pd.products_name LIMIT 5");
    while ($popular = tep_db_fetch_array($products_query_raw)) {
    echo '<tr><td>'.$popular['products_name'].'</td><td>'.$popular['products_ordered'].'</td></tr>';
        }
    ?>
    
    </table>
       </td>
       </tr></table></td>
   </tr><thead>
   <tr>
    <th><?php echo BOX_SSL_STATUS; ?></th>
    <th colspan="2">ECJC Online Shop Information</th>
    
   </tr></thead>
   <tr>
      <td>
      <?php
      if (getenv('HTTPS') == 'on') {
    $size = ((getenv('SSL_CIPHER_ALGKEYSIZE')) ? getenv('SSL_CIPHER_ALGKEYSIZE') . '-bit' : '<i>' . BOX_CONNECTION_UNKNOWN . '</i>');
    echo tep_image(DIR_WS_ICONS . 'locked.gif', ICON_LOCKED, '', '', 'align="right"') . sprintf(BOX_CONNECTION_PROTECTED, $size);
    }else{
    echo tep_image(DIR_WS_ICONS . 'unlocked.gif', ICON_UNLOCKED, '', '', 'align="right"') . BOX_CONNECTION_UNPROTECTED;
    }
    ?>
    </td>
    
    <td>
<a href="http://www.joomla-host.co.za/index.php?option=com_versions" target="_BLANK"><?php echo MOSCOM_VERSION ?> - Check Version</a><br>
    <a target=_blank href="http://www.joomla-host.co.za/Hosting/" target="_BLANK">Cheap Reliable Hosting</a>
    
    </td>
    
    <td>
    <a target=_blank href="http://www.joomla-host.co.za" target="_blank">ECJC Project Site</a><br>
    <a target=_blank href="http://www.joomla-host.co.za/List-forums/ECJC-Online-Shop.html" target="_BLANK"> ECJC Community forum</a> 
    
                      </td>
                      </tr>
  </table>
<!-- Start Required Template Info -->
  <table width="100%" align="center" class="adminlist"><thead><tr> <th class="config">Important Info and Install FAQ</th></tr></thead>
                <tr><td align="center">
<table>
<td align="center"><a href="index3.php?option=com_oscommerce&osMod=faqs">Click Here for more install and setup tips!</a></td>
</table>
</tr>
 </td>
   </table>
<!-- End Required Template Info -->   
 </td>     
      </tr>
      <tr>
        <td><?php require(DIR_WS_INCLUDES . 'footer.php'); ?></td>
      </tr>
    </table></td>
  </tr>
</table>
         
                <!--
<table width="100%" class="adminheading">                
                -->
<?php
  require(DIR_WS_INCLUDES . 'application_bottom.php');
  // -- webMS Modification --
  // reset the Mambo Database connection (stomped by osCommerce Connection)
  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
?>
